package com.example.forjava.controller;

import com.example.forjava.entity.ListUser;
import com.example.forjava.entity.Trader;
import com.example.forjava.util.GenericJsonResult;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;


@RestController
@RequestMapping(value = "/json")
public class JsonController {

    @RequestMapping(value = "/jsonTest")
    public GenericJsonResult<ListUser> aopTest(String id) {
        ListUser response = new ListUser();
        if (StringUtils.equals("1", id)) {
            response.setId(id);
        } else {
            List<Trader> list = new ArrayList<>();
            list.add(new Trader("Alice", "Cambridge"));
            list.add(new Trader("Bob", "New York"));
            response.setList(list);
        }

        return new GenericJsonResult(response);
    }

}
